<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : baseinfo.manage.php   FILE_PATH : \\system\baseinfo.manage.php
 * ....基本信息设置管理
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Wed Sep 19 14:09:31 CST 2007
 */

require ("../global.inc.php");
class SysBaseInfoManage extends SystemFrameWork{
	/**
	 * 基本信息对象
	 *
	 * @var obj
	 */
	var $obj_baseinfo;
	/**
	 * 商城支付方式对象
	 *
	 * @var obj
	 */
	var $obj_pay;
	/**
	 * 分页对象
	 *
	 * @var obj
	 */
	var $obj_page;
	function main(){
		/**
		 * 初始化分页类
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}
		/**
		 * 
		 */
		if (!is_object($this->obj_pay)){
			require_once ("pay_accounts.class.php");
			$this->obj_pay = new payAccountsClass();
		}
		/**
		 * 创建配置文件操作对象
		 */
		if (!is_object($this->obj_baseinfo)){
			require_once ("baseinfo.class.php");
			$this->obj_baseinfo = new BaseInfoClass();
		}
		/**
		 * 创建设置对象
		 */
		if (!is_object($this->obj_settings)){
			require_once('settings.class.php');
			$this->obj_settings = new SettingsClass();
		}
		/**
		 * 语言包
		 */
		$this->getlang("baseinfo");

		switch ($this->_input['action']){
			case "save":
				$this->_saveBaseInfo();
				break;
			case "list":
				$this->_input['action'] = "setting";
				$this->_getBaseInfo();
				break;
			case 'payset':
				$this->setPayAccounts();
				break;
			case 'savepay':
				$this->savePayAccounts();
				break;
			case "del_pic":
				$this->_del_pic();
				break;
			default:
				$this->_getBaseInfo();
		}
	}

	/**
	 * 得到基本信息
	 *
	 */
	function _getBaseInfo(){
		//商城系统设置
		if ($this->_input['action'] == 'system'){
			
		}

		//邮件发送类型
		if($this->_input['action'] == 'mail'){
			$email_send_type = $this->obj_settings->getSettings('email_send_type');
			$this->output('email_send_type', $email_send_type);
		}

		/**
		 * 页面输出
		 */
		if (is_array($this->_configinfo)){
			foreach ($this->_configinfo as $k=>$v){
				$this->output('baseinfo_' . $k . '_array', $v);
			}
		}
		$this->showpage("sys_baseinfo." . $this->_input['action']);
	}

	/**
	 * 保存基本信息
	 *
	 */
	function _saveBaseInfo(){
		//清理模板缓存文件
		$this->obj_baseinfo->clear_templates_cache('../templates');
		//检查附件存放文件夹是否有效
		if ($this->_input['genre'] == 'system'){
			if (!is_dir(BasePath.'/'.$this->_input['txtattachmentspath'])){
				$this->redirectPath('error','',$this->_lang['errBAccessoriesSaveDirIsNotDir'],1);
			}
			if (!is_writable(BasePath.'/'.$this->_input['txtattachmentspath'])){
				$this->redirectPath('error','',$this->_lang['errBAccessoriesSaveDirIsNotWrite'],1);
			}
		}
		//邮件设置 保存发送类型
		if ($this->_input['genre'] == 'mail'){
			$value_array['variable'] = 'email_send_type';
			$value_array['section'] = 'email';
			$value_array['value'] = $this->_input['email_send_type'];
			$this->obj_settings->updateSettings($value_array);
			unset($value_array);
		}
		//上传图片
		if(isset($_FILES['txtimage_file']['name']) and $_FILES['txtimage_file']['name'] != ''){
			require_once("uploadfile.class.php");
			$upload = new UploadFile();
			$upload->error_msg_type = 1;
			$upload->allow_type = explode(',',$this->_fileconfig['allowuploadimagetype']);
			$upload->ifresize = false;
			$filename = $upload->upfile("txtimage_file");
			$this->_input["txtimage_name"] = $filename["getfilename"];
			unset($upload);
		}
		//其他需要执行的操作
		if ($this->_input['index_html'] == '0'){//首页动态
			/**
			 * 创建多语言对象
			 */
			if (!is_object($obj_language)){
				require_once("language.class.php");
				$obj_language = new LanguageClass();
			}
			//删除根目录文件
			$language_array = $obj_language->listLanguage($obj_condition,$obj_page);
			if (is_array($language_array)){
				for ($i=0;$i<count($language_array);$i++){
					if ($language_array[$i]['language_state'] == '1'){//默认语言
						if (file_exists('../index.html')){
							@unlink('../index.html');
						}
					}else {
						if (file_exists('../index_'.$language_array[$i]['language_path'].'.html')){
							@unlink('../index_'.$language_array[$i]['language_path'].'.html');
						}
					}
				}
			}
			unset($obj_language,$language_array);
		}
		//修改配置文件
		$this->obj_baseinfo->charset = $this->_configinfo['websit']['ncharset'];//编码
		$this->obj_baseinfo->modiBaseInfo($this->_input,$this->_input['genre']);
		//查看店铺缴费开关是否变动，如果变动 则更新入库
		if ($this->_input['shop_pay_mode'] != $this->_configinfo['paymode']['shop_pay_mode']){
			require_once('payment.class.php');
			$obj_payment = new PaymentClass();
			$array = array();
			$array['ps_date_line'] = time();
			$array['ps_type'] = 'shoppay';
			$array['ps_state'] = intval($this->_input['shop_pay_mode']);
			$array['ps_ip'] = $_SERVER['REMOTE_ADDR'];
			$obj_payment->addPaymentSwitch($array);
			unset($obj_payment,$array);
			//判断开关动作，更新会员扩展表字段
			require_once('member.class.php');
			$obj_member = new MemberClass();
			$obj_member->updateMemberPayTime($this->_input['shop_pay_mode']);
		}
		if($this->_input['shop_pay_mode'] == '1'){
			//保存试用期数值
			$value_array = array();
			$value_array['variable'] = 'shoppay_product_num';
			$value_array['section'] = 'shoppay';
			if($this->_input['txt_shoppay_product'] != ''){
				$value_array['value'] = (abs($this->_input['txt_shoppay_product']) == $this->_input['txt_shoppay_product'])?$this->_input['txt_shoppay_product']:'0';
			}else{
				$value_array['value'] = '0';
			}
			$this->obj_settings->updateSettings($value_array);
			$value_array = array();
			$value_array['variable'] = 'shoppay_shop_time';
			$value_array['section'] = 'shoppay';
			if($this->_input['shoppay_shop'] != ''){
				$value_array['value'] = (abs($this->_input['shoppay_shop']) == $this->_input['shoppay_shop'])?$this->_input['shoppay_shop']:'0';
			}else{
				$value_array['value'] = '0';
			}
			$this->obj_settings->updateSettings($value_array);
		}
			
		switch($this->_input['genre']){
			case 'setting':
				//记录操作日志
				SystemPowerClass::addSysLog($this->_lang['langBSystemInfoSave']);
				$return_url = './baseinfo.manage.php?action=setting';
				break;
			case 'mail':
				//记录操作日志
				SystemPowerClass::addSysLog($this->_lang['langBSystemLogMail']);
				$return_url = './baseinfo.manage.php?action=mail';
				break;
			case 'system':
				//记录操作日志
				SystemPowerClass::addSysLog($this->_lang['langBSystemLogSystem']);
				$return_url = './baseinfo.manage.php?action=system';
				break;
		}
		
		//删除缓存文件，防止内容被缓存，页面内容不更新
		@unlink('../cache/configini.cache.php');
		$this->redirectPath('error',$return_url,$this->_lang['langBSaveInfoOk'],1);
	}

	/**
	 * 设置商城支付帐号
	 * 
	 */
	function setPayAccounts(){
		//取帐号配置文件信息
		$paymentinfo = $this->_getconfigini("payment.ini.php");
		foreach ($paymentinfo as $k=>$v){
			$this->output('paymentinfo_' . $k . '_array', $v);
		}
		/**
		 * 页面输出
		 */
		$this->output("paymentinfo",$paymentinfo);
		$this->showpage("sys_baseinfo.pay");
	}

	/**
	 * 保存商城支付帐号
	 * 
	 */
	function savePayAccounts(){
		//修改配置文件
		$this->obj_baseinfo->charset = $this->_configinfo['websit']['ncharset'];//编码
		$this->obj_baseinfo->modiPaymentInfo($this->_input,'online');

		//记录操作日志
		SystemPowerClass::addSysLog($this->_lang['langBSystemSavePay']);

		$this->redirectPath("error","",$this->_lang['langBSaveInfoOk'],1);
	}

	/**
	 * 删除图片操作
	 */
	function _del_pic(){
		if ($this->_input['type'] == 'wm_image') {//水印图片
			if (file_exists(BasePath.'/'.$this->_configinfo['gdimage']['wm_image_name'])){
				unlink(BasePath.'/'.$this->_configinfo['gdimage']['wm_image_name']);
				//更新ini
				$array['wm_image'] = '';
			}
		}
		$this->obj_baseinfo->modiBaseInfo($array,'image');
		Common::outMessage("json",'',1);
	}
}

$baseinfo = new SysBaseInfoManage();
$baseinfo->main();
unset($baseinfo);
?>